<?
session_start();
ob_start();
//============ Start Session และทำการเรียก Function ติดต่อฐานข้อมูล 
require("connect/connect.php");
require("connect/function.php");

//============ กรณีที่ทำการล็อกอินสมาชิก
if($_GET["action"]=="Login")
{
	//============ ตรวจสอบสมาชิก
	$resultLogin=select("member","where 1 and Email='".$_POST["txtEmailSC"]."' and Password='".$_POST["txtPassSC"]."' ");
	if(!$resultLogin)
	{
						echo "<script language=\"JavaScript\">";
						echo "alert('อีเมล์ และ รหัสผ่าน ไม่ถูกต้อง');";
						echo "</script>";
	}
	else
	{
				//============ บันทึกข้อมูลสมาชิก
					  $_SESSION["strEmail"]=$_POST["txtEmailSC"];
					  $_SESSION["strPassword"]=$_POST["txtPassSC"];
					  session_write_close();
					  header("location: member_detail.php");	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include('scripts/popup.php'); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:322px;
	height:360px;
	z-index:1;
	left: 0px;
	top: 13px;
	background-image: url(image/login.png);
}
.style3 {
	color: #999999;
	font-family: Arial, Helvetica, sans-serif;
}
h1,h2,h3,h4,h5,h6 {
	font-family: Arial, Helvetica, sans-serif;
}
.style31 {color: #999999;
	font-family: Arial, Helvetica, sans-serif;
}
.style31 {color: #333333}
body,td,th {
	font-size: 12px;
}
-->
</style>
</head>

<body>

<div id="apDiv1">
  <div align="center">
    <label></label>
    <p align="left"></p>
    <p align="left"></p>
    <p align="left"></p>
    <p align="left"></p>
       <?
	if($_SESSION["strEmail"] =="")
	{
	?>
    <form name="frmLogin" action="?action=Login" method="post">
    <table width="94%" height="331" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="1%" height="111">&nbsp;</td>
        <td width="35%">&nbsp;</td>
        <td width="2%">&nbsp;</td>
        <td width="62%">&nbsp;</td>
      </tr>
      <tr>
        <td height="36">&nbsp;</td>
        <td><div align="right" class="style3"><strong>USERNAME</strong></div></td>
        <td>&nbsp;</td>
        <td><input name="txtEmailSC" type="text" class="txtbox" id="txtEmailSC" size="15" /></td>
      </tr>
      <tr>
        <td height="22">&nbsp;</td>
        <td><div align="right" class="style31">
          <p class="style3"><strong>PASSWORD</strong><br />
          </p>
        </div></td>
        <td>&nbsp;</td>
        <td><input name="txtPassSC" type="password" class="txtbox" id="txtPassSC" size="15" /></td>
      </tr>
      <tr>
        <td height="54" rowspan="2">&nbsp;</td>
        <td colspan="3" align="right"><div align="right"><table width="173" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="20"><a target="_blank"></td>
                <td width="68"><input name="submit" type="image"  value="Log in" src="image/button/login_button_03.png" align="top" /></td>
                <td width="85"><a href="../register.php" target="_blank"><img src="image/button/login_button_05.png" width="84" height="46" /></a></td>
              </tr>
          </table></div></td>
      </tr>
      <tr>
        <td colspan="3" align="center">ลืมรหัสผ่าน: <font color="#FF0000"><a href="forget.php" class="popup">คลิก</a></font></td>
      </tr>
      <tr>
        <td height="54">&nbsp;</td>
        <td colspan="3" align="center" valign="top">      <?
	  }
	  else
	  {
	  ?>
      <table width="100%" height="246" border="0" cellspacing="0">
        <tr> 
          <td colspan="4" align="center" class="style5 style45">
          <p>&nbsp;</p>
          <p><img src="image/address-book-icon.png" width="103" height="136" />
          </p>
          <div align="center"><strong>ยินดีต้อนรับ:
		  <? echo $_SESSION["strEmail"];?>
          </strong></div></td>
        </tr>
        <tr> 
          <td width="24%" align="right" class="style5 style45"><a href="payment.php" target="_blank"><font color="#FF0000"><img src="image/create.gif" alt="" width="15" height="15" align="absmiddle" /></font></a></td>
          <td width="23%" align="right" class="style5 style45"><a href="payment.php" class="popup"><font color="#FF0000"> แจ้งชำระเงิน </font></a></td>
          <td class="style5 style45">&nbsp;</td>
          <td class="style5 style45"><a href="profile.php" target="_blank"><font color="#FF0000">แก้ไขข้อมูลส่วนตัว</font></a></td>
        </tr>
        <tr> 
          <td height="19" colspan="2" align="right" valign="top"><a href="cart.php" class="popup"><font color="#FF0000"><img src="image/cart.gif" alt="" width="23" height="17" align="absmiddle" />สินค้าในตะกร้า</font></a></td>
          <td width="5%">&nbsp;</td>
          <td width="48%"><a href="logout.php"><font color="#FF0000">ออกจากระบบ </font></a></td>
          </tr>
      </table>
      <?
	  }
	  ?>
      <div align="center"><br>
        <br>
      </div></td>
  </tr>
</table>
	</form>
</td>
      </tr>
    </table>
    <p align="left">&nbsp; </p>
    <p align="left">&nbsp;</p>
    <p align="left">&nbsp;</p>
    <p align="left">&nbsp;</p>
    <p align="left">&nbsp;</p>
  </div>
</div>
</body>
</html>
